package gov.cn.user.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import gov.cn.user.entity.UserInfo;
import gov.cn.user.exception.UserException;
import gov.cn.user.mapper.UserMapper;
import gov.cn.user.service.LoginService;
import gov.cn.user.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl extends ServiceImpl<UserMapper, UserInfo> implements LoginService {


    @Override
    public void login(UserInfo userInfo) throws UserException {
        QueryWrapper<UserInfo> wrapper = new QueryWrapper<UserInfo>();
        // 页面ID
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(userInfo.getUserName()), UserInfo::getUserName, userInfo.getUserName());

        UserInfo user = this.baseMapper.selectOne(wrapper);
        if (null==user){
            throw new UserException("用户名不存在");
        }
        if (!user.getPassword().equals(userInfo.getPassword())){
            throw new UserException("密码不正确");
        }
    }
}
